<template>
  <j-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    :maskClosable="false"
    :keyboard="false"
    v-bind:prefixNo="prefixNo"
    switchHelp
    switchFullscreen
    @ok="handleOk"
    @cancel="handleCancel"
    wrapClassName="ant-modal-cust-warp"
    :id="prefixNo"
    style="top:5%;height: 110%;overflow-y: hidden">
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
        <a-row class="form-row" :gutter="24">
          <a-col :lg="6" :md="12" :sm="24">
            <!-- <a-form-item  label="渠道来源" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input placeholder="请输入渠道来源" v-decorator.trim="[ 'source', validatorRules.source]"/>
            </a-form-item> -->
            <a-form-item label="渠道来源" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-select placeholder="请输入渠道来源" v-decorator.trim="[ 'source', validatorRules.source]"  :dropdownMatchSelectWidth="false"
           showSearch optionFilterProp="children" disabled >
             <a-select-option v-for="(item,index) in sourceList" :key="index" :value="item.name" >{{ item.name }}</a-select-option>
          </a-select>
        </a-form-item>
          </a-col>
          <a-col :lg="6" :md="12" :sm="24">
            <a-form-item label="客户姓名" :labelCol="labelCol" :wrapperCol="wrapperCol" >
              <a-input placeholder="请输入客户姓名" disabled v-decorator.trim="[ 'name', validatorRules.name]" />
            </a-form-item>
          </a-col>
          <a-col :lg="6" :md="12" :sm="24">
            <a-form-item label="联系号码" :labelCol="labelCol" :wrapperCol="wrapperCol" >
          <a-input placeholder="请输入联系号码" disabled :maxLength="11" v-decorator.trim="[ 'tel', validatorRules.tel]" />
        </a-form-item>                        
          </a-col>
          <a-col :lg="6" :md="12" :sm="24">
            <a-form-item label="身份证号码" :labelCol="labelCol" :wrapperCol="wrapperCol" >
          <a-input placeholder="请输入身份证号码" disabled :maxLength="18" v-decorator.trim="[ 'idNumber', validatorRules.idNumber]"/>
        </a-form-item>
          </a-col>
          <a-col :lg="6" :md="12" :sm="24">
            <a-form-item label="门店名称" :labelCol="labelCol" :wrapperCol="wrapperCol" >
              <a-select placeholder="请输入门店名称" disabled v-decorator.trim="[ 'storeName', validatorRules.storeName]"  :dropdownMatchSelectWidth="false"
           showSearch optionFilterProp="children">
                <a-select-option v-for="(item,index) in storeNameList" :key="index" :value="item" >{{ item }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :lg="6" :md="12" :sm="24">
            <a-form-item label="地址" :labelCol="labelCol" :wrapperCol="wrapperCol" >
          <a-input placeholder="请输入地址" disabled v-decorator.trim="[ 'address', validatorRules.address]"/>
        </a-form-item>
          </a-col>
          <a-col :lg="6" :md="12" :sm="24">
            <a-form-item label="业务员" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-select placeholder="请输入业务员" v-decorator.trim="[ 'ope', validatorRules.ope]" :disabled="[1,2,3].indexOf(opeType) != -1 ? false : true"  :dropdownMatchSelectWidth="false"
           showSearch optionFilterProp="children">
             <a-select-option v-for="(item,index) in opeList" :key="index" :value="item.name" >{{ item.name }}</a-select-option>
          </a-select>
        </a-form-item>
      </a-col>
      <a-col :lg="6" :md="12" :sm="24">
        <a-form-item label="开单时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-date placeholder="请输入开单时间" :disabled="opeType == 1 ? false : true" v-model="model.startTime" v-decorator.trim="[ 'startTime', validatorRules.startTime]" ></j-date>
        </a-form-item>
      </a-col>
        </a-row>
        <a-row class="form-row" :gutter="24">
          <a-col :lg="6" :md="12" :sm="24">
            <a-form-item label="业务类型" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-select placeholder="请输入业务类型" v-decorator.trim="[ 'type', validatorRules.type]" disabled :dropdownMatchSelectWidth="false"
           showSearch optionFilterProp="children">
               <a-select-option v-for="(item,index) in typeList" :key="index" :value="item.name" >{{ item.name }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <!-- <a-col :lg="8" :md="12" :sm="24" v-show="(opeType == 1 || model.type != '回收') ? false : true"> -->
          <a-col :lg="8" :md="12" :sm="24" v-show="((opeType != 1 && model.type == '回收') || (opeType == 2 && (model.type == '寄存' || model.type == '过桥')) || (opeType == 2 && model.type == '续存')) ? true : false">
            <a-form-item label="出货价/还款金额" :labelCol="labelCol" :wrapperCol="wrapperCol" >
              <a-input placeholder="请输入出货价/还款金额" :disabled="(opeType == 4 || opeType == 6 || opeType == 7)? true : false" v-model="model.deliveryPrice" v-decorator.trim="[ 'deliveryPrice', validatorRules.deliveryPrice]"/>
            </a-form-item>
          </a-col>
          <a-col :lg="6" :md="12" :sm="24">
            <!-- <a-form-item :label="model.type == '回收'?'出货时间':'还款时间'" :labelCol="labelCol" :wrapperCol="wrapperCol" > -->
            <a-form-item label="操作时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-date dateFormat="YYYY-MM-DD HH:mm:ss" v-model="model.updateTime" :disabled="(opeType == 4 || opeType == 6 || opeType == 7)? true : false"></j-date>
            </a-form-item>
          </a-col>
        </a-row>
        <!-- <a-table :columns="materialTable.columns"  :data-source="materialTable.dataSource" bordered>
          <template #name="{ text }">
            <a>{{ text }}</a>
          </template>
        </a-table> -->
             <j-editable-table id="deliveryModal" :ref="refKeys[0]"
             :loading="materialTable.loading"
             :disabled="true"
          :columns="materialTable.columns" :dataSource="materialTable.dataSource" :maxHeight="300" :rowNumber="false"
           :actionButton="true" :dragSort="true">
        </j-editable-table>
      
        <a-row class="form-row" :gutter="24" style="margin-top: 30px;">
          <a-col :lg="8" :md="12" :sm="24" v-show="model.type !== '回收'">
            <a-form-item label="寄存时长服务费率" :labelCol="labelCol" :wrapperCol="wrapperCol" >
              <a-select placeholder="请输入寄存时长服务费率" @change="ChangeRate" :disabled="(opeType == 1 || opeType == 2 || opeType == 3)? false : true" v-decorator.trim="[ 'rate', validatorRules.rate]"  :dropdownMatchSelectWidth="false"
           showSearch optionFilterProp="children">
             <a-select-option v-for="(item,index) in rateList" :key="index" :value="item" >{{ item }}</a-select-option>
          </a-select>
            </a-form-item>
          </a-col>
          <a-col :lg="6" :md="12" :sm="24" v-if="this.model.id" v-show="model.type !== '回收'">
            <a-form-item label="收益" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input placeholder="请输入收益"  :read-only="rate.index < 3" v-model="model.profit"  v-decorator.trim="[ 'profit', validatorRules.profit]" :disabled="(opeType == 4 || opeType == 6 || opeType == 7)? true : false"/>
              <!-- <a-input placeholder="请输入收益"  :read-only="rate.index < 3" v-model="model.profit" :disabled="(opeType == 4 || opeType == 6)? true : false"/> -->
            </a-form-item>
          </a-col>          
          <a-col :lg="10" :md="12" :sm="24" v-show="model.type !== '回收'">
            <a-form-item label="寄存到期时间记录/出货时间" :labelCol="labelCol" :wrapperCol="wrapperCol" >
          <j-date dateFormat="YYYY-MM-DD" v-model="model.endTime" :read-only="rate.index < 3" :disabled="(opeType == 4 || opeType == 6 || opeType == 7)? true : false"></j-date>
        </a-form-item>
          </a-col>
          <a-col :lg="11" :md="12" :sm="24" v-if="opeType != 6 ">
            <a-form-item label="到期提醒" :labelCol="labelCol" :wrapperCol="wrapperCol" >
          <a-textarea :rows="7" placeholder="请输入到期提醒" :disabled="((opeType == 4 || opeType == 6 || opeType == 7)|| opeType == 5) ? true : false" v-decorator.trim="[ 'reminder', validatorRules.reminder]" />
        </a-form-item>
          </a-col>
          <a-col :lg="11" :md="12" :sm="24" v-if="opeType != 6 ">
        <a-form-item label="其他备注" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-textarea :rows="7" placeholder="请输入其他备注" :disabled="(opeType == 4 || opeType == 6 || opeType == 7)? true : false" v-decorator.trim="[ 'remark', validatorRules.remark]" />
        </a-form-item>
          </a-col>
        </a-row>
        <a-row class="form-row" :gutter="24" v-if="opeType != 6 ">
          <a-col :lg="15" :md="12" :sm="24">
             <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="业务图片">
              <j-image-upload v-model="fileList" :disabled="((opeType == 1 || opeType == 3 || opeType == 2) ? false : true)"  v-decorator.trim="[ 'fileName', validatorRules.fileName]" bizPath="business" text="上传" isMultiple></j-image-upload>
             </a-form-item>
           </a-col>
        </a-row>
        <a-row class="form-row" :gutter="24" v-if="opeType != 6 ">
          <a-col :lg="15" :md="12" :sm="24">
            <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="业务视频">
              <j-upload v-model="imgName" :disabled="((opeType == 1 || opeType == 3 || opeType == 2) ? false : true)" v-decorator.trim="[ 'imgName', validatorRules.imgName]" bizPath="bill" isMultiple></j-upload>
            </a-form-item>
          </a-col>
        </a-row>
        <a-row class="form-row" :gutter="24" v-if="opeType != 6 ">
          <a-col :lg="15" :md="12" :sm="24">
            <a-form-item label="行情收益反馈" :labelCol="labelCol" :wrapperCol="wrapperCol" >
              <a-textarea :rows="7" placeholder="请输入其他备注" disabled v-decorator.trim="[ 'feedback', validatorRules.feedback]" />
            </a-form-item>
          </a-col>
        </a-row>
        <a-row>
           <!--存放位置 -->
          <a-col :lg="6" :md="12" :sm="24" v-if="opeType == 6">
            <a-form-item label="存放位置" :labelCol="labelCol" :wrapperCol="wrapperCol" >
              <a-tree-select style="width:100%" :dropdownStyle="{maxHeight:'200px',overflow:'auto'}"
                           allow-clear :treeDefaultExpandAll="true"
                           :treeData="treeData"  v-decorator.trim="[ 'position', validatorRules.position]" placeholder="请选择存放位置">
            </a-tree-select>
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
    </a-spin>
    <template #footer>
      <a-button @click="handleCancel">取消</a-button>
      <!-- 
        :okText= 
      
      -->
      <a-button type="primary" :disabled="opeType == 6 && model.feedback != 0" @click="handleOk">{{ opeType == 4 ? '确定' : opeType == 6 ? '入库': opeType == 7 ? '冻结':'保存' }}</a-button>
    </template>
  </j-modal>
</template>
<script>
import { FormTypes } from '@/utils/JEditableTableUtil'
  import pick from 'lodash.pick'
  import { JEditableTableMixin } from '@/mixins/JEditableTableMixin'
  import JUpload from '@/components/jeecg/JUpload'
  import JDate from '@/components/jeecg/JDate'
  import JSelectPosition from '@/components/jeecgbiz/JSelectPosition'
  import JImageUpload from '../../../components/jeecg/JImageUpload'
  import { getAction } from '@/api/manage'
import { VALIDATE_NO_PASSED } from '@/utils/JEditableTableUtil'

  import Vue from 'vue'
  import { BusinessMixin } from '../mixins/BusinessMixin'
import { addBusPro,getOrganizationTree  } from '../../../api/api'
  export default {
    name: "BusinessEdit",
    mixins: [JEditableTableMixin,BusinessMixin],
    components: {
      JUpload,
      JDate,
      JSelectPosition,
      JImageUpload
    },
    data () {
      return {
        title:"操作",
        width: '1600px',
        moreStatus: false,
        // 新增时子表默认添加几行空数据
        addDefaultRowNum: 1,
        visible: false,
        supList: [],
        depotList: [],
        imgName:[],
        treeData:[],
       columns: {
        other: [
          {
            title: '物品类型', key: 'category', width: '7%', type: FormTypes.select, placeholder: '请选择${title}',
            options: [],
            validateRules: [{ required: true, message: '${title}不能为空' }]
          },
          {
            title: '物品鉴定级别', key: 'level', width: '7%', type: FormTypes.select, placeholder: '请选择${title}',
            options: [],
            validateRules: [{ required: true, message: '${title}不能为空' }]
          },
          {
            title: '数量', key: 'amount', width: '7%', type: FormTypes.inputNumber,
            validateRules: [{ required: true, message: '${title}不能为空' }]
          },
          {
            title: '品牌,规格,重量', key: 'brandWeight', width: '30%', type: FormTypes.input,
            validateRules: [{ required: true, message: '${title}不能为空' }]
          },
          {
            title: '寄存金额', key: 'depositAmount', width: '10%', type: FormTypes.inputNumber, statistics: true,
            validateRules: [{ required: false, message: '${title}不能为空' }]
          },
          {
            title: '当日行情价', key: 'daily', width: '10%', type: FormTypes.input,
            validateRules: [{ required: false, message: '${title}不能为空' }]
          }
        ],
        recycle: [
          {
            title: '物品类型', key: 'category', width: '7%', type: FormTypes.select, placeholder: '请选择${title}',
            options: [],
            validateRules: [{ required: true, message: '${title}不能为空' }]
          },
          {
            title: '物品鉴定级别', key: 'level', width: '7%', type: FormTypes.select, placeholder: '请选择${title}',
            options: [],
            validateRules: [{ required: true, message: '${title}不能为空' }]
          },
          {
            title: '数量', key: 'amount', width: '7%', type: FormTypes.inputNumber,
            validateRules: [{ required: true, message: '${title}不能为空' }]
          },
          {
            title: '品牌,规格,重量', key: 'brandWeight', width: '30%', type: FormTypes.input,
            validateRules: [{ required: true, message: '${title}不能为空' }]
          },
          {
            title: '当日行情价', key: 'daily', width: '10%', type: FormTypes.input,
            validateRules: [{ required: false, message: '${title}不能为空' }]
          },
          {
            title: '回收单价', key: 'recyclePrice', width: '10%', type: FormTypes.inputNumber, defaultValue: '', statistics: true,
            validateRules: [{ required: false, message: '${title}不能为空' }]
          },
          {
            title: '回收总价', key: 'recycleTotal', width: '10%', type: FormTypes.inputNumber, readonly: true, defaultValue: '0', statistics: true,
            validateRules: [{ required: false, message: '${title}不能为空' }]
          }],
        credit: [
          {
            title: '寄存金额', key: 'depositAmount', width: '10%', type: FormTypes.inputNumber, statistics: true, readonly: true, defaultValue: '0',
            validateRules: [{ required: false, message: '${title}不能为空' }]
          }
        ]
      },
        rate:{
          option:[{date:1, rate:3}, {date:10, rate:5}, {date:30, rate:10}],
          currentRate:0,
          index:-1
        },
        deposit:0,
        profit:0,
        operTimeStr: '',
        prefixNo: 'CGDD',
        sourceList:[],
        storeNameList:['沙市玉桥店', '公安一店'],
        opeList:[],
        typeList:[],
        fileList:[],
        produceList:[],
        model: {
          startTime:'',
          endTime:'',
          profit:'',
          deliveryPrice: '',
          recycleTotal: '',
          updateTime: ''
        },
        opeType: 0,
        engineerId:"",
        rateList:['1天-3%服务费率','10天-5%服务费率','一个月-10%服务费率','综合服务费','过桥5‰每天'],
        labelCol: {
          xs: { span: 24 },
          sm: { span: 8 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        refKeys: ['materialDataTable', ],
        tableKeys:['materialDataTable', ],
        activeKey: 'materialDataTable',
        materialTable:{
        loading: false,
          dataSource:[],
          columns:[]
        },
        confirmLoading: false,
        validatorRules:{
          position:{
            rules: [{
              required: true, message: '请选择存放位置'
            }]
          },
          source:{
            rules: [{
              required: true, message: '请输入渠道来源'
            }]
          },
          date:{
            rules: [{
              required: true, message: '请输入到期日期'
            }]
          },
          startTime:{
            rules: [{
              required: true, message: '请输入开单时间'
            }]
          },
          name:{
            rules: [{
              required: true, message: '请输入客户名称'
            }]
          },
          tel:{
            rules: [{
              required: true,type: 'number',message: '请输入正确格式的联系号码(11位)', trigger: 'blur',
               transform (value) {
                  var moneyg = /^\d+$|^\d*\.\d+$/g
                  if (!moneyg.test(value) ) {
                    return false
                  }else{
                    if(value.length<11){
                      return false
                    }
                    return Number(value)
                  }
                }
            }]
          },
          idNumber:{
            rules: [{
              required: true,type: 'string', message: '请输入正确身份证号码', trigger: 'blur',
               transform (value) {
                var moneyg = /^\d+X?$/g
                  if (!moneyg.test(value) ) {
                    return false
                  }else{
                    if(value.length<18){
                      return false
                    }
                    return value
                  }
                }
            }]
          },
          storeName:{
            rules: [{
              required: true, message: '请输入门店名称'
            }]
          },
          address:{
            rules: [{
              required: false, message: '请输入联系地址'
            }]
          },
          type:{
            rules: [{
              required: true, message: '请输入业务类型'
            }]
          },
          deliveryPrice:{
            rules: [{
              required: true,
               message: '请输入正确的出货价/还款金额',type: 'number', trigger: 'blur',
               transform (value) {
                  if(value == '' || value == undefined){
                    return ''
                  }
                  var moneyg = /^\d+$|^\d*\.\d+$/g
                  if (!moneyg.test(value) ) {
                    return false
                  }else{
                    return Number(value)
                  }
                }
            }]
          },
          feedback:{
            rules: [{
              // required: true,
               message: '请输入行情收益反馈'
            }]
          },
          profit:{
            rules: [{
                required:true,
               message: '请输入收益'
            }]
          },
          rate:{
            rules: [{
              // required: true,
               message: '请输入寄存时长服务费率'
            }]
          },
          ope:{
            rules: [{
              required: true, message: '请输入业务员姓名'
            }]
          },
          endTime:{
            rules: [{
              // required: true,
               message: '请输入寄存到期时间/出货时间'
            }]
          },
          reminder:{
            rules: [{
              // required: true,
               message: '请输入到期提醒'
            }]
          },
          remark:{
            rules: [{
              // required: false,
               message: '请输入其他备注'
            }]
          },
          fileName:{
            rules: [{
              // required: true,
               message: '请上传业务图片'
            }]
          },
          imgName:{
            rules: [{
              // required: true,
               message: '请上传业务图片'
            }]
          }
        },
        url: {
          // add是新增的接口
          edit: '/business/updateBusinessAndItem'
        }
      }
    },
    created () {
      const token = Vue.ls.get(ACCESS_TOKEN);
      this.headers = {"X-Access-Token":token};
    },
    mounted(){
      this.getTreeByParams({
        id:''
      })
    },
    watch:{
      model:{
        handler(value){
          if(this.rate.option[this.rate.index] instanceof Object && value.startTime !== ''){
            // 到期时间记录 = 开单时间 + 寄存时长
            let date = new Date(value.startTime)
            if(this.rate.option[this.rate.index].rate == 10){
            this.model.endTime = this.formDate(new Date(date.setMonth(date.getMonth() + 1)))
          }else{
            this.model.endTime = this.formDate(new Date(date.setDate(date.getDate() + this.rate.option[this.rate.index].date)))
          }
          }
          if(this.model.type == '回收'){
            // 收益 等于 出货价 减去 回收总价
            let profit = Number(this.model.deliveryPrice) - Number(this.model.recycleTotal)
            this.model.profit = profit.toFixed(2)
            this.form.fieldsStore.fields.profit.value = Number(this.model.profit).toFixed(2)
          }
          // 寄存时，进行变现操作，并且寄存时长服务位综合/过桥
          if(this.opeType == 2 && (this.model.type == '寄存' || this.model.type == '过桥') && (this.rate.option[this.rate.index] instanceof Object)){
            // 如果为空
            if(this.model.deliveryPrice == '' || this.model.deliveryPrice == null){
              this.model.profit = this.profit
            }else{
              this.model.profit = Number(this.profit) + (Number(this.model.deliveryPrice) - Number(this.deposit))
            }
            this.form.fieldsStore.fields.profit.value = Number(this.model.profit).toFixed(2)
          }
        },deep:true
      }
    },
    methods: {
      getTreeByParams(params) {
      getOrganizationTree(params).then((res) => {
        if (res) {
          this.treeData = []
          for (let i = 0; i < res.length; i++) {
            this.treeData.push(res[i])
          }
        }
      })
    },
      formDate(date){
            const year = date.getFullYear();
            const month = String(date.getMonth() + 1).padStart(2, '0');
            const day = String(date.getDate()).padStart(2, '0');
            const hours = String(date.getHours()).padStart(2, '0');
            const minutes = String(date.getMinutes()).padStart(2, '0');
            const seconds = String(date.getSeconds()).padStart(2, '0');
            const dateString = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
            return dateString
        },
      ChangeRate(value,event){
        this.rate.index = event.data.key
        if(this.rate.option[event.data.key] instanceof Object){
          this.profit = (this.deposit * (this.rate.option[this.rate.index].rate / 100)).toFixed(2)
          // 收益 = 寄存金额 * 服务费率
          this.model.profit = (this.deposit * (this.rate.option[this.rate.index].rate / 100)).toFixed(2)
          this.rate.currentRate = this.rate.option[this.rate.index].rate
          // 到期时间记录 = 开单时间 + 寄存时长
          let date = new Date(this.model.startTime)
          if(this.rate.option[this.rate.index].rate == 10){
            this.model.endTime = this.formDate(new Date(date.setMonth(date.getMonth() + 1)))
          }else{
            this.model.endTime = this.formDate(new Date(date.setDate(date.getDate() + this.rate.option[this.rate.index].date)))
          }
        }
        this.form.fieldsStore.fields.profit.value = Number(this.model.profit).toFixed(2)
      },
      validateFormAndTables(form){
      if (!(form && typeof form.validateFields === 'function')) {
        throw `form 参数需要的是一个form对象，而传入的却是${typeof form}`
      }
      return new Promise((resolve, reject) => {
        // 验证主表表单
        form.validateFields((err, values) => {
          err ? reject({ error: VALIDATE_NO_PASSED }) : resolve(values)
        })
      })
    },
    /** 确定按钮点击事件 */
    handleOk() {
      if(this.opeType == 4){
        this.close()
        return
      }
     
        /** 一次性验证主表和所有的次表 */
      this.validateFormAndTables(this.form)
      .then(allValues => {
        if (typeof this.classifyIntoFormData !== 'function') {
          throw this.throwNotFunction('classifyIntoFormData')
        }
        let formData = this.classifyIntoFormData(allValues)
        if(this.opeType == 6){
          // if(this.position.trim() == '' || this.position == null){
            // this.$message.error('请选择存放位置')
            // return
          // }
          addBusPro({
            ...formData
          }).then(res=>{
            if(res.code === 200){
              this.$emit('ok')
              this.close() 
              this.$message.success('入库成功')
            } 
          }).catch(err=>{
            this.$message.error('入库失败') 
          })
          return
        }
        // else if(this.opeType == 7){
        //     addBusPro({
        //     ...formData
        //   }).then(res=>{
        //     if(res.code === 200){
        //       this.$emit('ok')
        //       this.close() 
        //       this.$message.success('冻结成功')
        //     } 
        //   }).catch(err=>{
        //     this.$message.error('入库失败') 
        //   })
        //   return
        // }
        // 发起请求
        return this.request(formData)
      }).catch(e => {
        if (e.error === VALIDATE_NO_PASSED) {
          // 如果有未通过表单验证的子表，就自动跳转到它所在的tab
          this.activeKey = e.index == null ? this.activeKey : this.refKeys[e.index]
        } else {
          console.error(e)
        }
      })
    },
    init_(){
      this.rate.currentRate = 0
      this.rate.index = -1
    },
      editCus(record,opeType,url) {
        this.opeType = opeType
            // 详情页，所有的都不允许修改
        if (typeof this.editBefore === 'function') this.editBefore(record)
          this.visible = true
        this.init_()
        // 续存或者还款，变现操作 这里的业务员 可以修改
        // this.getOperatorList({})

        this.getBusinessList({}).then(res => {
          this.getSourceList({})
          this.getOperatorList({})
  
          this.activeKey = this.refKeys[0]
          this.form.resetFields()
          if (typeof this.editAfter === 'function') this.editAfter(record.id,url)
        })
    },
    //调用完edit()方法之后会自动调用此方法
      editAfter(id,url) {
          // 加载子表数据
          let params = {
            businessId : id
          }
          let that = this
          getAction(url,params).then(res=>{
            that.model = Object.assign({},res.data)
            that.model.opeType = that.opeType
            this.model.startTime = res.data.startTimeStr
            this.model.endTime = res.data.endTimeStr

            this.model.updateTime = res.data.updateTimeStr

            // 只有变现的时候才会出现 出货价/还款金额 字段
            if(that.opeType !== 2){
              that.validatorRules.deliveryPrice.rules[0].required = false
            }
              
            that.$nextTick(() => {
              that.form.setFieldsValue(pick(that.model,'source','name','tel','idNumber','address','storeName','deliveryPrice','profit','feedback','ope','type','rate','status','endTime','reminder','remark','fileName','imgName','startTime','updateTime'))
            })
            console.log(this.model.type,'this.model.type');
          that.initType(this.model.type)
            that.deposit = 0
            that.profit = 0
         if (this.model.profit !== null)
          that.profit = this.model.profit
        res.data.itemList.forEach(item => {
          that.deposit += Number.parseFloat(item.depositAmount)
        })
        let len = that.materialTable.dataSource.length
        for (let i = 0; i < len; i++)
          that.materialTable.dataSource.pop()
        // 方法一（插入数据）
        that.materialTable.dataSource.push(...res.data.itemList)
        if (that.model.type === "回收") {
          let recycleTotal = 0
          res.data.itemList.forEach(item => {
            recycleTotal += Number(item.recycleTotal)
          })
          that.model.recycleTotal = recycleTotal
        }
        let index = this.rateList.indexOf(this.model.rate)
        if (index !== -1) {
          this.rate.index = index
          this.rate.currentRate = this.rateList[index].rate
        }
          })
      },
          initType(type) {
            console.log(this.typeList,'this.typeList');
      for (var i = 0; i < this.typeList.length; i++) {
        var oneSubject = this.typeList[i]
        console.log(type, oneSubject.name);
        if (type === oneSubject.name) {
          let arr = oneSubject.categoryList
          let changeTypeColumns = () => {
            let clean_arr = () => {
              let len = this.materialTable.columns.length
              for (let i = 0; i < len; i++) {
                this.materialTable.columns.pop()
              }
              // this.materialTable.columns.splice(0,this.materialTable.length)
            }
            if (type === "回收") {
              clean_arr()
              this.materialTable.columns.push(...this.columns.recycle)
              console.log(this.materialTable.columns,'this.materialTable.columns');
            } else if (type === '信用贷款') {
              // 信用贷款列
              clean_arr()
              this.materialTable.columns.push(...this.columns.credit)
            }
            else {
              console.log('other');
              // 其他列
              clean_arr()
              this.materialTable.columns.push(...this.columns.other)
            }
          }
          // 修改为空
          changeTypeColumns()
          this.materialTable.columns[0].options = []
          for (let i = 0; i < arr.length; i++) {
            let depotInfo = {};
            depotInfo.value = arr[i].name  //注意-此处value必须为字符串格式
            depotInfo.text = arr[i].name
            depotInfo.title = arr[i].name
            depotInfo.levelList = arr[i].levelList
            this.materialTable.columns[0].options.push(depotInfo)
          }
        }
      }
    },
      /** 整理成formData */
      classifyIntoFormData(allValues) {
        let billMain = Object.assign(this.model,allValues)
        delete billMain.createTimeStr2
        delete billMain.endTime2
        return {
          id: this.model.id,
          info: JSON.stringify(billMain),
          rows: JSON.stringify([...this.materialTable.dataSource]),
        }
      },
    }
      
  }
</script>
<style scoped>

</style>